using System.Drawing;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Ruminate.GUI.Framework;
using Ruminate.Utils;
using Color = Microsoft.Xna.Framework.Color;
using Point = Microsoft.Xna.Framework.Point;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace Ruminate.GUI.Content {

    public class IconRenderer: Renderer {
        
        public Point IconSize { get; set; }
        public int Depth { get; set; }

        public IconRenderer(Texture2D imageMap, Point iconSize, int depth,
            RuminateGUI gui) : base(gui, imageMap) {

            IconSize = iconSize;
            Depth = depth;
        }

        public Texture2D Render(int offset) {

            var baker = new TextureBaker(GraphicsDevice, IconSize.ToVector2(), RenderState.Fill);

            baker.Draw(
                ImageMap, 
                Vector2.Zero,
                new Rectangle(0, IconSize.Y * offset, IconSize.X, IconSize.Y),
                Color.White);

            return baker.GetTexture();
        }

        public Texture2D Render(Point size, int offset, TextRenderer textRenderer, string label) {
 
            var baker = new TextureBaker(
                GraphicsDevice,
                new Vector2(IconSize.X, IconSize.Y), 
                RenderState.Fill);

            baker.Draw(
                ImageMap,
                Vector2.Zero,
                new Rectangle(0, IconSize.Y * offset, IconSize.X, IconSize.Y),
                Color.White);

            var icon = baker.GetTexture();

            var text = textRenderer.Render(size, label, 
                TextHorizontal.LeftAligned, 
                TextVertical.CenterAligned);

            baker = new TextureBaker(GraphicsDevice, size.ToVector2(), RenderState.Fill);
            baker.Draw(icon, Vector2.Zero, Color.White);
            baker.Draw(text, new Vector2(IconSize.X + 2, 0), Color.White);
            return baker.GetTexture(RotateFlipType.RotateNoneFlipNone);
        }
    }
}
